/****** Object:  StoredProcedure [dbo].[spChiTietNhapSanPham]    Script Date: 09/29/2012 19:01:04 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spChiTietNhapSanPham]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spChiTietNhapSanPham]
GO

/****** Object:  StoredProcedure [dbo].[spChiTietNhapSanPham]    Script Date: 09/29/2012 19:01:04 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

create procedure [dbo].[spChiTietNhapSanPham]
		@masp nvarchar(16),
		@tungay datetime,
		@denngay datetime	
WITH ENCRYPTION	
AS
	Begin
		Select pn.SoPN, pn.NgayNhapKho, sp.MaThuoc, sp.TenHoatChat, sp.TenBietDuoc, sp.NongDoHamLuong, 
		       pn.SoHD AS SoDangKy, sp.QuyCach, sp.NhaSX, lk.SoLo, ctn.SoLuong, ctn.DonGia 
		From tbl_SanPham sp
		INNER JOIN tbl_LuuKho lk ON sp.MaThuoc = lk.MaThuoc
		INNER JOIN tbl_ChiTietPhieuNhap ctn ON lk.MaLuuKho = ctn.MaLuuKho
		INNER JOIN tbl_PhieuNhap pn ON pn.SoPN = ctn.SoPN	 
		Where sp.MaThuoc = @masp 
		  AND ((@tungay is null) or (convert(date, @tungay) <= convert(date, pn.NgayNhapKho)))
		  AND ((@denngay is null) or (convert(date, @denngay) >= convert(date, pn.NgayNhapKho)))	
		  
		Select * from tbl_CongTy  
	End

GO


